<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>            
                    <p:commandButton id="btnSearch" ajax="false" value="Process Due Age" action="#{creditCompanyDueController.createInwardAgeTable()}" onclick="onSubmitButton();" />
                    <p:commandButton id="btnProcess" ajax="false" 
                                     value="Process Due Age(Excel)" 
                                     action="#{creditCompanyDueController.createInwardAgeDetailAnalysis}" onclick="onSubmitButton();" />
                    <p:commandButton value="Excel" ajax="false" actionListener="#{creditCompanyDueController.createInwardAgeDetailAnalysis}" >
                        <pe:exporter target="lstDue" fileName="inward_due_age_credit_company_detail" type="xlsx" />
                    </p:commandButton>
                    <p:defaultCommand target="btnSearch"/>

                    <p:dataTable id="lst" value="#{creditCompanyDueController.creditCompanyAge}" var="i" rendered="#{creditCompanyDueController.creditCompanyAge.size() > 0.0}" >                       
                        <p:column headerText="Dealor Name" filterBy="#{i.institution.name}">       
                            <h:outputLabel id="colComDetailDue"  value="#{i.institution.name}"/>
                            <p:tooltip for="colComDetailDue"  >
                                <h:outputLabel value="Address : #{i.institution.address}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Tel : #{i.institution.mobile}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Fax : #{i.institution.fax}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="E-Mail : #{i.institution.email}" >
                                </h:outputLabel>
                            </p:tooltip>
                        </p:column>                               
                        <p:column headerText="0-30">   
                            <p:panel style="float: top;">
                                <p:dataTable value="#{i.value1PatientEncounters}" var="p1" >
                                    <p:column>
                                        <p:commandLink id="colp1Detail"  value="#{p1.bhtNo}"
                                                       action="#{bhtSummeryFinalizedController.createBhtBillFinalized}">
                                            <f:setPropertyActionListener value="#{p1}" target="#{bhtSummeryFinalizedController.patientEncounter}"/>   
                                        </p:commandLink>
                                        <p:tooltip for="colp1Detail"  >
                                            <h:outputLabel value="Duration Days : #{p1.transDayCount}" >
                                            </h:outputLabel>
                                            <br/>
                                            <h:outputLabel value="Ploicy Number : #{p1.policyNo}" >
                                            </h:outputLabel>
                                            <br/>
                                            <h:outputLabel value="Referance Number : #{p1.referanceNo}" >
                                            </h:outputLabel>
                                            <br/>
                                            <h:outputLabel value="Credit Limit : #{p1.creditLimit}" >
                                            </h:outputLabel>
                                        </p:tooltip>
                                    </p:column>
                                    <p:column>
                                        #{p1.patient.person.name}
                                    </p:column>
                                    <p:column>
                                        <h:outputLabel value="#{p1.dateOfAdmission}" >
                                            <f:convertDateTime pattern="dd MM yy"/>
                                        </h:outputLabel>                                    
                                    </p:column>
                                    <p:column>
                                        <h:outputLabel value="#{p1.dateOfDischarge}" >
                                            <f:convertDateTime pattern="dd MM yy"/>
                                        </h:outputLabel>                                      
                                    </p:column>
                                    <p:column>
                                        <h:outputLabel value="#{p1.finalBill.netTotal-(p1.finalBill.paidAmount+p1.creditPaidAmount)}" >
                                            <f:convertNumber pattern="#,##0.00"/>
                                        </h:outputLabel>  
                                        <f:facet name="footer" >
                                            <h:outputLabel  value="#{i.value1}" style="float:  right;">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>

                                </p:dataTable>
                            </p:panel>

                        </p:column>
                        <p:column headerText="30-60" style="text-align: right;">    

                            <p:dataTable value="#{i.value2PatientEncounters}" var="p1">
                                <p:column>
                                    <p:commandLink id="colp2Detail"  value="#{p1.bhtNo}"
                                                   action="#{bhtSummeryFinalizedController.createBhtBillFinalized}">
                                        <f:setPropertyActionListener value="#{p1}" target="#{bhtSummeryFinalizedController.patientEncounter}"/>   
                                    </p:commandLink>
                                    <p:tooltip for="colp2Detail"  >
                                        <h:outputLabel value="Duration Days : #{p1.transDayCount}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Ploicy Number : #{p1.policyNo}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Referance Number : #{p1.referanceNo}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Credit Limit : #{p1.creditLimit}" >
                                        </h:outputLabel>
                                    </p:tooltip>
                                </p:column>
                                <p:column>
                                    #{p1.patient.person.name}
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.dateOfAdmission}" >
                                        <f:convertDateTime pattern="dd MM yy"/>
                                    </h:outputLabel>                                    
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.dateOfDischarge}" >
                                        <f:convertDateTime pattern="dd MM yy"/>
                                    </h:outputLabel>                                      
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.finalBill.netTotal-(p1.finalBill.paidAmount+p1.creditPaidAmount)}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>  
                                    <f:facet name="footer" >
                                        <h:outputLabel  value="#{i.value2}" style="float:  right;">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>
                        </p:column>
                        <p:column headerText="60-90" style="text-align: right;">                           
                            <p:dataTable value="#{i.value3PatientEncounters}" var="p1">
                                <p:column>
                                    <p:commandLink id="colp3Detail"  value="#{p1.bhtNo}"
                                                   action="#{bhtSummeryFinalizedController.createBhtBillFinalized}">
                                        <f:setPropertyActionListener value="#{p1}" target="#{bhtSummeryFinalizedController.patientEncounter}"/>   
                                    </p:commandLink>
                                    <p:tooltip for="colp3Detail"  >
                                        <h:outputLabel value="Duration Days : #{p1.transDayCount}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Ploicy Number : #{p1.policyNo}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Referance Number : #{p1.referanceNo}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Credit Limit : #{p1.creditLimit}" >
                                        </h:outputLabel>
                                    </p:tooltip>
                                </p:column>
                                <p:column>
                                    #{p1.patient.person.name}
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.dateOfAdmission}" >
                                        <f:convertDateTime pattern="dd MM yy"/>
                                    </h:outputLabel>                                    
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.dateOfDischarge}" >
                                        <f:convertDateTime pattern="dd MM yy"/>
                                    </h:outputLabel>                                      
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.finalBill.netTotal-(p1.finalBill.paidAmount+p1.creditPaidAmount)}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>  
                                    <f:facet name="footer" >
                                        <h:outputLabel  value="#{i.value3}" style="float:  right;">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>
                        </p:column>
                        <p:column headerText="90 More" style="text-align: right;">   
                            <h:outputLabel  value="#{i.value4}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                            <p:dataTable value="#{i.value4PatientEncounters}" var="p1">
                                <p:column>
                                    <p:commandLink id="colp4Detail"  value="#{p1.bhtNo}"
                                                   action="#{bhtSummeryFinalizedController.createBhtBillFinalized}">
                                        <f:setPropertyActionListener value="#{p1}" target="#{bhtSummeryFinalizedController.patientEncounter}"/>   
                                    </p:commandLink>
                                    <p:tooltip for="colp4Detail"  >
                                        <h:outputLabel value="Duration Days : #{p1.transDayCount}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Ploicy Number : #{p1.policyNo}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Referance Number : #{p1.referanceNo}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Credit Limit : #{p1.creditLimit}" >
                                        </h:outputLabel>
                                    </p:tooltip>
                                </p:column>
                                <p:column>
                                    #{p1.patient.person.name}
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.dateOfAdmission}" >
                                        <f:convertDateTime pattern="dd MM yy"/>
                                    </h:outputLabel>                                    
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.dateOfDischarge}" >
                                        <f:convertDateTime pattern="dd MM yy"/>
                                    </h:outputLabel>                                      
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{p1.finalBill.netTotal-(p1.finalBill.paidAmount+p1.creditPaidAmount)}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:facet name="footer" >
                                        <h:outputLabel  value="#{i.value4}" style="float:  right;">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>
                        </p:column>                      
                    </p:dataTable>


                    <p:dataTable id="lstDue" value="#{creditCompanyDueController.dealerDueDetailRows}"
                                 var="r" 
                                 rendered="#{creditCompanyDueController.dealerDueDetailRows.size() > 0.0}">   
                        <p:columnGroup type="header">
                            <p:row>  
                                <p:column rowspan="2" headerText="Dealor Name"/> 
                                <p:column rowspan="2" headerText="Dealor NetTotal"/> 
                                <p:column colspan="6" headerText="0-30"/>
                                <p:column colspan="6" headerText="30-60"/> 
                                <p:column colspan="6" headerText="60-90"/> 
                                <p:column colspan="6" headerText="90 more"/> 
                            </p:row> 
                            <p:row>  
                                <p:column headerText="Dealor Tolal"/>
                                <p:column headerText="BHT No"/>  
                                <p:column headerText="Patient"/>
                                <p:column headerText="Admit Date"/> 
                                <p:column headerText="Discharge Date"/> 
                                <p:column headerText="Total"/> 

                                <p:column headerText="Dealor Tolal"/>
                                <p:column headerText="BHT No"/>  
                                <p:column headerText="Patient"/>
                                <p:column headerText="Admit Date"/> 
                                <p:column headerText="Discharge Date"/> 
                                <p:column headerText="Total"/> 

                                <p:column headerText="Dealor Tolal"/>
                                <p:column headerText="BHT No"/>  
                                <p:column headerText="Patient"/>
                                <p:column headerText="Admit Date"/> 
                                <p:column headerText="Discharge Date"/> 
                                <p:column headerText="Total"/> 

                                <p:column headerText="Dealor Tolal"/>
                                <p:column headerText="BHT No"/>  
                                <p:column headerText="Patient"/>
                                <p:column headerText="Admit Date"/> 
                                <p:column headerText="Discharge Date"/> 
                                <p:column headerText="Total"/> 
                            </p:row>
                        </p:columnGroup>


                        <p:column headerText="Dealor Name" >       
                            <h:outputLabel id="colComDetailDue"  value="#{r.dealer.name}"/>
                            <p:tooltip for="colComDetailDue"  >
                                <h:outputLabel value="Address : #{r.dealer.address}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Tel : #{r.dealer.mobile}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Fax : #{r.dealer.fax}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="E-Mail : #{r.dealer.email}" >
                                </h:outputLabel>
                            </p:tooltip>
                        </p:column>
                        <p:column headerText="0-30" style="color: blue;" styleClass="numberCol" > 
                            <h:outputLabel value="#{r.zeroToThirty+r.thirtyToSixty+r.sixtyToNinty+r.moreThanNinty}" rendered="#{(r.zeroToThirty+r.thirtyToSixty+r.sixtyToNinty+r.moreThanNinty)ne 0.0}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>
                        <p:column headerText="0-30" style="color: blue;" styleClass="numberCol" > 
                            <h:outputLabel value="#{r.zeroToThirty}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column>
                            <h:outputLabel id="colp1DetailDue"  value="#{r.zeroToThirtyEncounter.bhtNo}"/>
                            <p:tooltip for="colp1DetailDue"  >
                                <h:outputLabel value="Ploicy Number : #{r.zeroToThirtyEncounter.policyNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Referance Number : #{r.zeroToThirtyEncounter.referanceNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Credit Limit : #{r.zeroToThirtyEncounter.creditLimit}" >
                                </h:outputLabel>
                            </p:tooltip>
                        </p:column>
                        <p:column>
                            <p:outputLabel value="#{r.zeroToThirtyEncounter.patient.person.name}" >
                            </p:outputLabel>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.zeroToThirtyEncounter.dateOfAdmission}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                    
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.zeroToThirtyEncounter.dateOfDischarge}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                      
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.zeroToThirtyEncounter.finalBill.netTotal-(r.zeroToThirtyEncounter.finalBill.paidAmount+r.zeroToThirtyEncounter.creditPaidAmount)}" rendered="#{(r.zeroToThirtyEncounter.finalBill.netTotal-(r.zeroToThirtyEncounter.finalBill.paidAmount+r.zeroToThirtyEncounter.creditPaidAmount))ne 0.0}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column styleClass="numberCol" > 
                            <h:outputLabel value="#{r.thirtyToSixty}" style="color: blue;">
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column>
                            <h:outputLabel id="colp1DetailDue2"  value="#{r.thirtyToSixtyEncounter.bhtNo}"/>
                            <p:tooltip for="colp1DetailDue2"  >
                                <h:outputLabel value="Ploicy Number : #{r.thirtyToSixtyEncounter.policyNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Referance Number : #{r.thirtyToSixtyEncounter.referanceNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Credit Limit : #{r.thirtyToSixtyEncounter.creditLimit}" >
                                </h:outputLabel>
                            </p:tooltip>
                        </p:column>
                        <p:column>
                            <p:outputLabel value="#{r.thirtyToSixtyEncounter.patient.person.name}" >
                            </p:outputLabel>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.thirtyToSixtyEncounter.dateOfAdmission}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                    
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.thirtyToSixtyEncounter.dateOfDischarge}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                      
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.thirtyToSixtyEncounter.finalBill.netTotal-(r.thirtyToSixtyEncounter.finalBill.paidAmount+r.thirtyToSixtyEncounter.creditPaidAmount)}" rendered="#{(r.thirtyToSixtyEncounter.finalBill.netTotal-(r.thirtyToSixtyEncounter.finalBill.paidAmount+r.thirtyToSixtyEncounter.creditPaidAmount))ne 0.0}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column styleClass="numberCol" > 
                            <h:outputLabel value="#{r.sixtyToNinty}" style="color: blue;" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column>
                            <h:outputLabel id="colp1DetailDue3"  value="#{r.sixtyToNintyEncounter.bhtNo}"/>
                            <p:tooltip for="colp1DetailDue3"  >
                                <h:outputLabel value="Ploicy Number : #{r.sixtyToNintyEncounter.policyNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Referance Number : #{r.sixtyToNintyEncounter.referanceNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Credit Limit : #{r.sixtyToNintyEncounter.creditLimit}" >
                                </h:outputLabel>
                            </p:tooltip>
                        </p:column>
                        <p:column>
                            <p:outputLabel value="#{r.sixtyToNintyEncounter.patient.person.name}" >
                            </p:outputLabel>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.sixtyToNintyEncounter.dateOfAdmission}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                    
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.sixtyToNintyEncounter.dateOfDischarge}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                      
                        </p:column>
                        <p:column styleClass="numberCol" >
                            <h:outputLabel value="#{r.sixtyToNintyEncounter.finalBill.netTotal-(r.sixtyToNintyEncounter.finalBill.paidAmount+r.sixtyToNintyEncounter.creditPaidAmount)}" rendered="#{(r.sixtyToNintyEncounter.finalBill.netTotal-(r.sixtyToNintyEncounter.finalBill.paidAmount+r.sixtyToNintyEncounter.creditPaidAmount))ne 0.0}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column styleClass="numberCol"> 
                            <h:outputLabel value="#{r.moreThanNinty}" style="color: blue;" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                        <p:column>
                            <h:outputLabel id="colp1DetailDue4"  value="#{r.moreThanNintyEncounter.bhtNo}"/>
                            <p:tooltip for="colp1DetailDue4"  >
                                <h:outputLabel value="Ploicy Number : #{r.moreThanNintyEncounter.policyNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Referance Number : #{r.moreThanNintyEncounter.referanceNo}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Credit Limit : #{r.moreThanNintyEncounter.creditLimit}" >
                                </h:outputLabel>
                            </p:tooltip>
                        </p:column>
                        <p:column>
                            <p:outputLabel value="#{r.moreThanNintyEncounter.patient.person.name}" >
                            </p:outputLabel>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.moreThanNintyEncounter.dateOfAdmission}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                    
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{r.moreThanNintyEncounter.dateOfDischarge}" >
                                <f:convertDateTime pattern="dd MM yy"/>
                            </h:outputLabel>                                      
                        </p:column>
                        <p:column styleClass="numberCol" >
                            <h:outputLabel value="#{r.moreThanNintyEncounter.finalBill.netTotal-(r.moreThanNintyEncounter.finalBill.paidAmount+r.moreThanNintyEncounter.creditPaidAmount)}" rendered="#{(r.moreThanNintyEncounter.finalBill.netTotal-(r.moreThanNintyEncounter.finalBill.paidAmount+r.moreThanNintyEncounter.creditPaidAmount))ne 0.0}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>  
                        </p:column>

                    </p:dataTable>
                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
